<div class="bjui-pageContent">
    <form action="{:U('writeGroup')}" class="pageForm" data-toggle="validate" method="post">
        <input type="hidden" name="rules" value="">
        <input type="hidden" name="id" value="{:I('get.groupId')}">
    </form>
    <ul id="ztree" class="ztree" data-toggle="ztree" data-options="{checkEnable:true,expandAll:true}" data-nodes='<?php echo json_encode($nodeList);?>'></ul>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
        <li><button type="submit" class="btn-default" data-icon="save">保存</button></li>
    </ul>
    <a data-icon="undo" onclick="$(this).navtab('reloadForm', true)" href="javascript:;" class="btn btn-orange"> 刷新</a>
</div>
<script>
    // 提交规则验证
    $(".in button[type=submit]").mouseup(function () {
        var treeObj = $.fn.zTree.getZTreeObj("ztree");
        var nodes = treeObj.getCheckedNodes(true);
        var ids = [];
        for(var i in nodes){
            if(Number(nodes[i].authId)>0){
                ids.push(nodes[i].authId);
            }
        }
        $("input[name=rules]").val(JSON.stringify(ids));
    })

    /**
     * 递归处理树形结构
     * @param ids
     * @param treeNode
     * @returns {*}

    function getChildren(ids,treeNode){
        console.log(treeNode.id);
        ids.push(treeNode.id);
        if (treeNode.isParent){
            for(var obj in treeNode.children){
                getChildren(ids,treeNode.children[obj]);
            }
        }
        return ids;
    }
    */
</script>

